﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.Workflow.Model;
using System.Data.Common;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.WebUI
{
    public class BatchActAcc : Honestysoft.Workflow.BusinessLogic.IWFActAccessorial
    {
        // 摘要:
        //     流程退回的后续操作(A发给B后,B执行了退回操作)
        //
        // 参数:
        //   pWFReturn:
        //
        //   pWFDbTransaction:
        public void WFBackAccessorial(WFReturn pWFReturn, DbTransaction pWFDbTransaction)
        {
            string dataId = pWFReturn.FromBuDatas[0].BuDataID;
            BaseObject.BaseBusinessLogic<Bu_AuditBatch> bll = new BaseObject.BaseBusinessLogic<Bu_AuditBatch>();
            Bu_AuditBatch batch = bll.GetEntity(dataId, pWFDbTransaction);
            if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Active).ToString();
                batch.CloseUser = "";
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
            else if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Output).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString();
                batch.CloseUser = "";
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
        }
        //
        // 摘要:
        //     流程收回的后续操作(A发给B后,B未处理时,A执行了收回操作)
        //
        // 参数:
        //   pWFReturn:
        //
        //   pWFDbTransaction:
        public void WFRecallAccessorial(WFReturn pWFReturn, DbTransaction pWFDbTransaction)
        {
            string dataId = pWFReturn.FromBuDatas[0].BuDataID;
            BaseObject.BaseBusinessLogic<Bu_AuditBatch> bll = new BaseObject.BaseBusinessLogic<Bu_AuditBatch>();
            Bu_AuditBatch batch = bll.GetEntity(dataId, pWFDbTransaction);
            if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Active).ToString();
                batch.CloseUser = "";
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
            else if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Output).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString();
                batch.CloseUser = "";
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
        }
        //
        // 摘要:
        //     流程启动的后续操作
        //
        // 参数:
        //   pWFReturn:
        //
        //   pWFDbTransaction:
        public void WFStartAccessorial(WFReturn pWFReturn, DbTransaction pWFDbTransaction)
        {
            //string dataId = pWFReturn.FromBuDatas[0].BuDataID;
            //BaseObject.BaseBusinessLogic<Bu_AuditBatch> bll = new BaseObject.BaseBusinessLogic<Bu_AuditBatch>();
            ////实际开始日期
            //bll.UpdateColumn("StartDate", DateTime.Now, dataId, pWFDbTransaction);
            //bll.UpdateColumn("BatchStatus", ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Active).ToString(), dataId, pWFDbTransaction);
        }
        //
        // 摘要:
        //     流程处理的后续操作(A发给B后执行的操作)
        //
        // 参数:
        //   pWFReturn:
        //
        //   pWFDbTransaction:
        public void WFTransAccessorial(WFReturn pWFReturn, DbTransaction pWFDbTransaction)
        {
            string dataId = pWFReturn.FromBuDatas[0].BuDataID;
            BaseObject.BaseBusinessLogic<Bu_AuditBatch> bll = new BaseObject.BaseBusinessLogic<Bu_AuditBatch>();
            //new Honestysoft.Financing.BusinessLogic.Audit("").ComputeBatchTable(dataId, pWFDbTransaction);
            Bu_AuditBatch batch = bll.GetEntity(dataId, pWFDbTransaction);
            if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Active).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString();
                batch.CloseUser = pWFReturn.EmployeeID;
                ////批次的锁定时间即为实际结束时间
                //batch.EndDate = DateTime.Now;
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
            else if (batch.BatchStatus == ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Lock).ToString())
            {
                batch.BatchStatus = ((int)Honestysoft.Financing.Model.EnumItem.BatchStatus.Output).ToString();
                batch.CloseUser = pWFReturn.EmployeeID;
                
                bll.UpdateEntity(batch, pWFDbTransaction);
            }
        }
    }
}